﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
using Fatec.ControleEstoque.Data.Model;

namespace Fatec.ControleEstoque.Security.Providers
{
    public class CustomRoleProvider : RoleProvider
    {     

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            return new EstoqueEntities().Funcoes.Select(funcoes => funcoes.Nome_Funcao).ToArray<string>();            
        }

        public override string[] GetRolesForUser(string username)
        {
            return new EstoqueEntities().Usuarios.Where(usuario => usuario.User.Equals(username)).First().Funcoes.Select(uf => uf.Nome_Funcao).ToArray<string>(); 
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            return new EstoqueEntities().Usuarios.Where(usuario => usuario.User.Equals(username) && usuario.Funcoes.Where(uf => uf.Nome_Funcao.Equals(roleName)).Any()).Any(); 

        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}
